﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using LinkCard.Utils;
using DataHelper = LinkCard.Utils.DataHelper;

namespace LinkCard.CustomerView
{
    public partial class Article : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int nCategoryID = ConvertUtility.ToInt32(Page.RouteData.Values["cid"]);
            Int64 nID = ConvertUtility.ToInt64(Page.RouteData.Values["id"]);

            if (nCategoryID > 0 && nID > 0)
            {
                DataTable dt = DataHelper.SelectTable("MessageDetail", new SqlParameter("@MessageID", nID));
                if (dt.Rows.Count > 0)
                {
                    msgCate.Text = dt.Rows[0]["name"].ToString();
                    msgCate.NavigateUrl = "/tin-tuc-" + nCategoryID + "/m-3/" + LinkCard.Utils.Utilities.ConvertTextToUrl(dt.Rows[0]["name"].ToString()) + ".html";
                    msgContent.Text = dt.Rows[0]["msgContent"].ToString();
                    msgTitle.Text = dt.Rows[0]["msgTitle"].ToString();
                    msgLead.Text = dt.Rows[0]["msgLead"].ToString();
                    msgPostDate.Text = "Ngày " + ConvertUtility.ToDateTime(dt.Rows[0]["msgContent"]).ToString("dd/MM/yyyy");


                    string taghtml = "";
                    if (dt.Rows[0]["Tags"] != null && dt.Rows[0]["Tags"].ToString() != "")
                    {
                        List<string> strarr = new List<string>();
                        foreach (string s in dt.Rows[0]["Tags"].ToString().Split(','))
                        {
                            strarr.Add("<a href='/tu-khoa-" + nCategoryID + "/m-" + Page.RouteData.Values["mid"] + "/tag=" + s + ".html'>" + s + "</a>");
                        }
                        taghtml = string.Join(", ", strarr);
                    }
                    else
                    {
                        tagbox.Visible = false;
                    }
                    lsttag.InnerHtml = taghtml;


                    Page.Title = dt.Rows[0]["msgTitle"].ToString() + " - " + ConvertUtility.ToDateTime(dt.Rows[0]["msgContent"]).ToString("dd/MM/yyyy") + " - LinkCard";
                    Page.MetaDescription = Page.Title;
                    Page.MetaKeywords = "";
                }
            }
        }
    }
}